﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Reflection.Emit;
using WeifenLuo.WinFormsUI.Docking;
using T3K.SketchEditor.Core;

namespace T3K.SketchEditor.Forms {
       
    public class BaseForm : DockContent, IDisposable {
        private string _windowName;
        private T3K.SketchEditor.Core.EditorManager _editor = T3K.SketchEditor.Core.EditorManager.Instance;

        public T3K.SketchEditor.Core.EditorManager Editor {
            get { return _editor; }
            set { _editor = value; }
        }

        public BaseForm(string windowName) {
            _windowName = windowName;
            _editor.RegisterCommands(this, _windowName);
            base.Disposed += new EventHandler(BaseForm_Disposed);
        }

        public string GetWindowEventName(string eventName) {
            return string.Format("{0}.{1}", _windowName, eventName);
        }

        private BaseForm() { }

        #region Clean (Dispose and ~)
        ~BaseForm() {
            UnregisterWindow();
        }

        void UnregisterWindow() {
            _editor.UnregisterCommands(this, _windowName);
        }

        void BaseForm_Disposed(object sender, EventArgs e) {
            UnregisterWindow();
        }

        public new void Dispose() {
            UnregisterWindow();
            base.Dispose(true);
            GC.SuppressFinalize(this);
        }
        #endregion

        private void InitializeComponent() {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(BaseForm));
            this.SuspendLayout();
            // 
            // BaseForm
            // 
            this.ClientSize = new System.Drawing.Size(284, 266);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.Name = "BaseForm";
            this.ResumeLayout(false);

        }
    }
}
